package xiao.trip.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import xiao.trip.Do.loseDO;
import xiao.trip.dao.loseDAO;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class loseC {
    @Autowired
    loseDAO lose1;

    @RequestMapping("/lose")
    public String lose_ex(HttpServletRequest request , Model model, HttpSession session, loseDO lose){
        String loseId=lose.getLoseId();
        String loseTitle=lose.getLoseTitle();
        String characteristic=lose.getCharacteristic();
        String loseTime=lose.getLoseTime();
        String username=lose.getUsername();
        String userphone=lose.getUserphone();
        if (loseId!=null&&lose1.select_Id(loseId).size()==0){
            String hp="../static/img/" + (int)Math.floor(Math.random()*10) +".jpg";
            lose1.insert(loseTitle,loseTime,characteristic,username,loseId,userphone,hp);
        }
        session.setAttribute("lose_list",lose1.select_all());
        model.addAttribute("lose_li",session.getAttribute("lose_list"));
        return "user/lose";
    }
}
